﻿/// <summary>
/// <Filename>: Motion_Program.cs
/// Author: Jiang Xiaolong
/// Created: 2015.01.26
/// Version: 1.0
/// Company: Sunnytech
/// Function: Program运动信息处理类
///
/// Changed By:
/// Modification Time:
/// Discription:
/// <summary>
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System;
using Motion.MotionPlatform.Tools;
using System.Reflection;

using Expression.api;
using Expression.impl;

namespace Motion.MotionPlatform
{
	//基本功能类
	public class FunctionMotion : IMotion
	{
		//默认为Active
		public CurrentState State
		{
			get { return _state; }
			set { _state = value; }
		}
		private CurrentState _state = CurrentState.Active;
		//时间参数
		//正常速率时间
		public float StandardTime
		{
			get { return _standardTime; }
			set { _standardTime = value; }
		}
		private float _standardTime = 0f;
		//运动开始时间
		public float StartTime
		{
			get { return _startTime; }
			set { _startTime = value; }
		}
		private float _startTime = 0f;
		//运动结束时间
		public float EndTime
		{
			get { return _endTime; }
			set { _endTime = value; }
		}
		private float _endTime = 0f;

		//速率
		public float SpeedRate
		{
			get { return Motion_Data.SpeedRate; }
			set { Motion_Data.SpeedRate = value; }
		}
		//暂停状态
		public bool PauseControl
		{
			get { return Motion_Data.PauseControl; }
			set { Motion_Data.PauseControl = value; }
		}

		//运动类型
		public MotionType CurrentMotion = MotionType.MoveOnly;

		public CRSpline crSpline = new CRSpline();  //CR样条
		//private int currentIndex = 0;  //当前二分法找到的参数序号
		//private float viewTimeRate = 0f;  //二分法找到的参数对应的时间
		private float currentTimeRate = 0f;  //记录当前时间进程
		public float startTimeRate = 0f;  //记录变速时的当前时间进程
		private float restTime = 0f;  //剩余时间
		private float postTime = 0f;  //已经过去的时间
		private float lastFrameTime = 0f;  //记录上一帧时间

		//透明度
		public float transparent_percent;
		//是否高亮
		public bool isHighlighting;
		//部件信息存储sheet
		public string sheetName;
		public DataTable toolPos;
		//声音文件
		public string fileName;
		public static AudioSource audioSource = null;
		public static bool generalMotionSource;
		//变换材质
		public GameObject obj;
		public List<Material> oldMats;
		public List<Material> newMats;
		//画线，标记
		public UnityEngine.Object prefab;
		public string prefabName;
		public Vector3 markPosition;
		public Vector3 markEulerangle;
		public Vector3 markScale;
		public bool markShow;
		//影藏，显示
		public bool isHide;
		//设置变量值
		public string varID;
		//public float varValue;
		public object varValue;

		//当前选择物体
		public ArrayList my_choose;
		//是否跟随generalMotion仪器消失
		public bool generalMotion_Disappear;
		//是否在指定时间内消失
		public bool time_Disappear;

		public FunctionMotion()
		{
			my_choose = new ArrayList();
		}


		public void ListCopy(List<Transform> child_list, List<Transform> parent_list)
		{

		}

		//空物体
		public GameObject EmptyObj = null;

		public void Init()
		{
			restTime = EndTime;

			//透明
			if (CurrentMotion == MotionType.ToolTransparent)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("Transparent");
				if (!MotionPlatformData.st_Transparent && _t != null)
				{
					MotionPlatformData.st_Transparent = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}

				//如果
				ArrayList my_choose_tmp = new ArrayList();
				for (int m = 0; m < my_choose.Count; m++)
				{
					GameObject tmp_obj = (GameObject)my_choose[m];
					if (tmp_obj.renderer.materials[0].color.a < 1)
					{
						my_choose_tmp.Add(tmp_obj);
					}
				}

				if (MotionPlatformData.st_Transparent && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("ReflectionFunc");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { 1, my_choose_tmp, my_choose, transparent_percent };
					methodInfo.Invoke(MotionPlatformData.st_Transparent, flag, Type.DefaultBinder, para, null);
				}
			}
			//高亮
			else if (CurrentMotion == MotionType.ToolHighlighting)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("HighlightingControl");
				if (!MotionPlatformData.st_HightLighting && _t != null)
				{
					MotionPlatformData.st_HightLighting = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}

				if (MotionPlatformData.st_HightLighting && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("ReflectionFunc");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { my_choose, isHighlighting };
					methodInfo.Invoke(MotionPlatformData.st_HightLighting, flag, Type.DefaultBinder, para, null);
				}
			}
			//部件位置设置
			else if (CurrentMotion == MotionType.SetToolPos)
			{
				for (int i = 0, j = 0; i < toolPos.Rows.Count; i++)
				{
					DataRow dr = toolPos.Rows[i];
					if (my_choose.Contains(GameObject.Find(dr[0].ToString())))
					{
						Transform objTransform = null;
						bool isRight = true;
						try
						{
							objTransform = GameObject.Find(dr[0].ToString()).transform;
						}
						catch
						{
							UnityEngine.Debug.LogError(dr[0].ToString() + "，该物体在当前场景中不存在，请确认！");
							return;
						}
						objTransform.position = Motion_Compute.Vector3Conversion(dr[1].ToString(), ref isRight);
						if (!isRight)
						{
							UnityEngine.Debug.LogError(dr[1].ToString() + "，位置向量转化错误，请检查！");
							return;
						}
						objTransform.eulerAngles = Motion_Compute.Vector3Conversion(dr[2].ToString(), ref isRight);
						if (!isRight)
						{
							UnityEngine.Debug.LogError(dr[2].ToString() + "，角度向量转化错误，请检查！");
							return;
						}

						j++;
					}
				}
			}
			//声音
			else if (CurrentMotion == MotionType.MUSIC)
			{
				if (!audioSource.isPlaying)
				{
					audioSource.Play();
				}
			}
			//改变材质
			else if (CurrentMotion == MotionType.ChangeMat)
			{
				Material[] newMaterials = obj.renderer.materials;
				for (int i = 0; i < obj.renderer.materials.Length; i++)
				{
					if (oldMats.Contains(obj.renderer.materials[i]))
					{
						int index = oldMats.IndexOf(obj.renderer.materials[i]);

						newMaterials[i] = newMats[index];
					}
				}
				obj.renderer.materials = newMaterials;
			}
			//画线标记
			else if (CurrentMotion == MotionType.Mark)
			{
				GameObject markObject = null;
				//如果已存在标记物体
				foreach (Transform child in obj.transform)
				{
					if (child.gameObject.name == (obj.name + "~" + prefabName))
					{
						markObject = child.gameObject;
						break;
					}
				}
				//如果不存在，则创建物体
				if (markObject == null)
				{
					markObject = UnityEngine.Object.Instantiate(prefab) as GameObject;
					markObject.name = (obj.name + "~" + prefabName);
				}

				//父子关系,位置，角度，大小
				markObject.transform.parent = obj.transform;
				markObject.transform.localPosition = markPosition;
				markObject.transform.localEulerAngles = markEulerangle;
				markObject.transform.localScale = markScale;

				//是否显示
				markObject.renderer.enabled = markShow;
			}
			//隐藏显示
			else if (CurrentMotion == MotionType.HideShow)
			{
				for (int m = 0; m < my_choose.Count; m++)
				{
					if (((GameObject)my_choose[m]).renderer != null)
					{
						((GameObject)my_choose[m]).renderer.enabled = !isHide;
					}

					//如果物体的存在Collider
					if (((GameObject)my_choose[m]).collider != null)
					{
						((GameObject)my_choose[m]).collider.enabled = !isHide;
					}
				}
			}
			//设置公式表里面的参数值
			else if (CurrentMotion == MotionType.SetVariable)
			{
				VariableManager.SetValue(varID, varValue, false);

			}

		}

		//暂停控制
		public void Pause(bool play_status)  //接口方法
		{
			if (play_status)
			{
			}
			else
			{
			}
		}

		//速率控制
		public void ChangeRate(float current_rate, float current_time)  //接口方法
		{

		}

		//通用运动驱动函数
		public void Move(float current_time, float speed_rate, float delta_time)  //接口方法
		{
			if (TimeRate(current_time) > 1.001f || current_time > EndTime)
			{
				return;
			}
			else
			{
				lastFrameTime = current_time;
			}
		}

		//变速后的时间比率
		private float TimeRate(float current_time)
		{
			currentTimeRate = startTimeRate + (current_time - postTime) / restTime;
			return currentTimeRate;
		}

		//时间控制
		public bool TimesUp(float current_time)
		{
			if (current_time > EndTime)
			{
				//Debug.Log("Excel: " + currentTimeRate + "---" + (EndTime - lastFrameTime));
				if (EndTime - lastFrameTime > 0)  //最后没运行的时间修正
				{
					//Debug.Log("Excel: " + (EndTime - lastFrameTime));
					TimeCorrection(EndTime - lastFrameTime, SpeedRate);
				}

				if (!generalMotion_Disappear && time_Disappear)
				{
					if (CurrentMotion == MotionType.MUSIC)
					{
						audioSource.clip = null;
					}
				}
				return true;
			}
			else
				return false;
		}

		//后处理，主要是位置修正
		public void PostProcess()
		{
			//不跟随generalMotions消失，并在指定时间后消失
			if (!generalMotion_Disappear && time_Disappear)
			{
				//透明
				if (CurrentMotion == MotionType.ToolTransparent)
				{
					Type _t = Motion_TypeGet.MotionTypeGet("Transparent");
					if (!MotionPlatformData.st_Transparent && _t != null)
					{
						MotionPlatformData.st_Transparent = (MonoBehaviour)GameObject.FindObjectOfType(_t);
					}

					if (MotionPlatformData.st_Transparent && _t != null)
					{
						MethodInfo methodInfo = _t.GetMethod("ReflectionFunc2");
						BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
						object[] para = new object[] { 1, my_choose };
						methodInfo.Invoke(MotionPlatformData.st_Transparent, flag, Type.DefaultBinder, para, null);
					}
				}
				//高亮
				else if (CurrentMotion == MotionType.ToolHighlighting)
				{
					Type _t = Motion_TypeGet.MotionTypeGet("HighlightingControl");
					if (!MotionPlatformData.st_HightLighting && _t != null)
					{
						MotionPlatformData.st_HightLighting = (MonoBehaviour)GameObject.FindObjectOfType(_t);
					}

					if (MotionPlatformData.st_HightLighting && _t != null)
					{
						MethodInfo methodInfo = _t.GetMethod("ReflectionFunc2");
						BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
						object[] para = new object[] { my_choose };
						methodInfo.Invoke(MotionPlatformData.st_HightLighting, flag, Type.DefaultBinder, para, null);
					}
				}
				//声音
				else if (CurrentMotion == MotionType.MUSIC)
				{
					if (audioSource.isPlaying)
					{
						audioSource.Stop();
					}

					audioSource.clip = null;
				}
			}
		}

		//最后没运行的时间修正
		private void TimeCorrection(float delta_time, float speed_rate)
		{

		}
	}

	/// <summary>
	/// Program运动信息提取管理类，相当于工厂；
	/// </summary>
	public class Motion_ProgramInfoManager : IMotionInfoManager
	{
		/// <summary>
		/// 信息获取函数，用反射的方式创建Program相应的解析类；
		/// </summary>
		/// <param name="motion_symbol">当前运动标识符；</param>
		/// <param name="data_row">当前传入的Excel数据行；</param>
		/// <param name="row_id">当前行对应ID号；</param>
		/// <param name="group_table">当前Group数据表；</param>
		/// <param name="motion_list">简单运动类列表；</param>
		/// <param name="complex_motion_list">复合运动类列表；</param>
		/// <returns>解析是否正确；</returns>
		public bool InfoGet(string motion_symbol, int state, DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			string programID = ((string)data_row[2].ToString()).ToUpper();

			if (Motion_Data.MotionFunctionAllow(motion_symbol, programID, state))
			{
				if (Motion_Data.MotionFunctionClassDic[motion_symbol].ContainsKey(programID))
				{
					Type _t = Motion_TypeGet.MotionTypeGet("Motion.MotionPlatform." + Motion_Data.MotionFunctionClassDic[motion_symbol][programID]);
					//实例化相应的解析类
					IMotionFunctionInfo infoInstance = (IMotionFunctionInfo)Activator.CreateInstance(_t);

					////将Excel中参数转换成参数表里面的数据
					//Motion_Compute.ExcelDataAnalysis(ref data_row);
					return infoInstance.InfoGet(data_row, row_id, group_table, motion_list, complex_motion_list);
				}
				else
				{
					Debug.LogError("Program运动标志符：" + programID + "，不含有该运动标志符对应的解析类，请询问相关程序猿！");
					return false;
				}
			}
			else
			{
				return true;
			}
		}
	}


	/// <summary>
	/// 铜棒敲击；
	/// </summary>
	public class Motion_Program_TongBang : IMotionFunctionInfo
	{

		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			//铜棒运动时的父亲
			GameObject empty = new GameObject();
			empty.name = "copper_empty-" + row_id;
			Transform copperTrans = null;
			Transform firstObj = null;
			// Transform firstObjParent = null;
			List<Transform> parentList = new List<Transform>();
			List<Transform> childList = new List<Transform>();
			try
			{
				//铜棒
				copperTrans = GameObject.Find(MotionPlatformData.copperName).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(MotionPlatformData.copperName + "：在此场景中未能找到铜棒！");
				}
				return false;
			}
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion(data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TBGROUP", row_id) + "，铜棒运动Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TBGROUP", row_id) + "，铜棒运动Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			objName = (string)group_table.Rows[0][groupColumn].ToString();
			try
			{
				firstObj = GameObject.Find(objName).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TBGROUP", row_id) + "，铜棒运动Group第一个物体填写错误，" + objName + "该物体在场景中不存在！");
				}
				return false;
			}
			// firstObjParent = firstObj.parent;
			empty.transform.position = firstObj.position;
			empty.transform.eulerAngles = firstObj.eulerAngles;
			// firstObj.parent = empty.transform;
			for (int i = 1; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				Transform tempTrans = null;
				try
				{
					tempTrans = GameObject.Find(objName).transform;
				}
				catch
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				childList.Add(tempTrans);
				parentList.Add(tempTrans.parent);
				// tempTrans.parent = empty.transform;	
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TBGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}
			//敲击次数
			int copperTimes = Motion_Compute.IntConversion((string)data_row[4].ToString(), ref isRight);
			if (!isRight || copperTimes == 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("EXCEL", "TBTIMES", row_id) + "，铜棒敲击次数填写有错误！");
				}
				return false;
			}
			//铜棒离敲击点距离
			Vector3 disTBVec = Motion_Compute.Vector3Conversion((string)data_row[5].ToString(), ref isRight);
			if (!isRight || disTBVec.magnitude == 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("EXCEL", "TBDIS", row_id) + "，铜棒敲击距离填写有错误！");
				}
				return false;
			}
			float disTB = disTBVec.magnitude;  //铜棒移动距离
			//物体移动方向
			Vector3 dirTBVec = Motion_Compute.Vector3Conversion((string)data_row[6].ToString(), ref isRight);
			if (!isRight || dirTBVec.magnitude == 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("EXCEL", "TBDIR", row_id) + "，铜棒敲击物体移动方向填写有错误！");
				}
				return false;
			}
			//移动速度确定
			float copperHitSpeed = MotionPlatformData.copperHitSpeed;
			//检测是否有自定义速度
			if (data_row.Table.Columns.Count > 7)
			{
				if ((string)data_row[7].ToString() != "")
				{
					copperHitSpeed = Motion_Compute.FloatConversion((string)data_row[7].ToString(), ref isRight);
					if (!isRight || copperHitSpeed == 0)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("EXCEL", "TBSPEED", row_id) + "，铜棒自定义速度填写有错误！");
						}
						return false;
					}
				}
			}
			float copperBackSpeed = copperHitSpeed / 3f;
			//铜棒敲击一次移动距离
			float copperForwardDis = MotionPlatformData.copperForwardDis;
			//检测是否有自定义距离
			if (data_row.Table.Columns.Count > 8)
			{
				if ((string)data_row[8].ToString() != "")
				{
					copperForwardDis = Motion_Compute.FloatConversion((string)data_row[8].ToString(), ref isRight);
					if (!isRight || copperForwardDis == 0)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("EXCEL", "TBFORWARDDIS", row_id) + "，铜棒自定义敲击移动距离填写有错误！");
						}
						return false;
					}
				}
			}
			GameObject emptyPos = new GameObject();
			emptyPos.name = "copper_empty_position--" + row_id;
			//敲击类创建
			IList<IMotion> tempMotionList = new List<IMotion>();
			for (int i = 0; i < copperTimes; i++)
			{
				//铜棒敲击---New Class
				BasicMotion _simpleMotion = new BasicMotion();
				Vector3 motionVec = MotionPlatformData.copperVector * (disTB + i * copperForwardDis);
				_simpleMotion.CurrentMotion = MotionType.ProgramMove;
				_simpleMotion.ParentTrans = copperTrans;
				_simpleMotion.MoveSpeed = copperHitSpeed;
				_simpleMotion.StandardTime = motionVec.magnitude / copperHitSpeed;
				_simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime;
				//起始信息记录
				_simpleMotion.StartPos = copperTrans.position;
				_simpleMotion.StartEurler = copperTrans.eulerAngles;
				emptyPos.transform.position = _simpleMotion.StartPos;
				emptyPos.transform.eulerAngles = _simpleMotion.StartEurler;
				emptyPos.transform.Translate(motionVec, Space.Self);
				//终止信息记录
				_simpleMotion.EndPos = emptyPos.transform.position;
				_simpleMotion.EndEurler = emptyPos.transform.eulerAngles;
				_simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate;
				if (i == 0)
				{
					_simpleMotion.State = CurrentState.Active;
				}
				else
				{
					_simpleMotion.State = CurrentState.Future;
				}
				tempMotionList.Add(_simpleMotion);

				//被敲击物体瞬移---New Class
				BasicMotion _simpleMotion2 = new BasicMotion();
				_simpleMotion2.State = CurrentState.Future;
				_simpleMotion2.CurrentMotion = MotionType.SetPos;
				_simpleMotion2.ParentTrans = firstObj;
				_simpleMotion2.ListCopy(childList, parentList);
				//起始信息记录
				emptyPos.transform.position = empty.transform.position;
				emptyPos.transform.eulerAngles = empty.transform.eulerAngles;
				_simpleMotion2.StartPos = emptyPos.transform.position;
				_simpleMotion2.StartEurler = emptyPos.transform.eulerAngles;
				emptyPos.transform.Translate(dirTBVec.normalized * (i + 1) * copperForwardDis, Space.Self);
				//终止信息记录
				_simpleMotion2.EndPos = emptyPos.transform.position;
				_simpleMotion2.EndEurler = emptyPos.transform.eulerAngles;
				//时间记录
				_simpleMotion2.StandardTime = 0.05f;
				_simpleMotion2.EndTime = 0.05f;
				tempMotionList.Add(_simpleMotion2);

				//铜棒返回---New Class
				BasicMotion _simpleMotion3 = new BasicMotion();
				_simpleMotion3.State = CurrentState.Future;
				_simpleMotion3.CurrentMotion = MotionType.ProgramMove;
				_simpleMotion3.ParentTrans = copperTrans;
				_simpleMotion3.MoveSpeed = copperBackSpeed;
				_simpleMotion3.StandardTime = motionVec.magnitude / copperBackSpeed;
				_simpleMotion3.SpeedVector = -motionVec / _simpleMotion3.StandardTime;
				//起始信息记录
				_simpleMotion3.StartPos = _simpleMotion.EndPos;
				_simpleMotion3.StartEurler = _simpleMotion.EndEurler;
				//终止信息记录
				_simpleMotion3.EndPos = _simpleMotion.StartPos;
				_simpleMotion3.EndEurler = _simpleMotion.StartEurler;
				_simpleMotion3.EndTime = _simpleMotion3.StandardTime / _simpleMotion3.SpeedRate;
				tempMotionList.Add(_simpleMotion3);
			}
			complex_motion_list.Add(tempMotionList);
			GameObject.DestroyImmediate(emptyPos);
			GameObject.DestroyImmediate(empty);

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				Vector3 autoVec = -dirTBVec;
				autoAssembleContents[6] = autoVec.x + "," + autoVec.y + "," + autoVec.z;

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}

	/// <summary>
	/// 指定高度摆放；
	/// </summary>
	public class Motion_Program_BaiFang : IMotionFunctionInfo
	{

		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{

			Transform firstObj = null;
			List<Transform> parentList = new List<Transform>();
			List<Transform> childList = new List<Transform>();
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", row_id) + "，任意摆放运动Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", row_id) + "，任意摆放运动Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			objName = (string)group_table.Rows[0][groupColumn].ToString();
			try
			{
				firstObj = GameObject.Find(objName).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", row_id) + "，任意摆放运动Group第一个物体填写错误，" + objName + "该物体在场景中不存在！");
				}
				return false;
			}
			for (int i = 1; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				Transform tempTrans = null;
				try
				{
					tempTrans = GameObject.Find(objName).transform;
				}
				catch
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				childList.Add(tempTrans);
				parentList.Add(tempTrans.parent);
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}
			//参考物体
			Transform referTrans = null;
			try
			{
				referTrans = GameObject.Find((string)data_row[4].ToString()).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFREFER", row_id) + "，任意摆放运动参考物体填写错误！");
				}
				return false;
			}
			//判断是工具移出还是任意部件移动，默认为任意部件
			bool isTool = false;
			if (data_row.Table.Columns.Count >= 5)
			{
				if ((string)data_row[5].ToString() == "")
				{
					isTool = true;
				}
			}
			//任意部件移动信息提取
			Vector3 finalPos = new Vector3(0f, 0f, 0f);
			Vector3 finalEuler = new Vector3(0f, 0f, 0f);
			if (!isTool)
			{
				if (data_row.Table.Columns.Count >= 7)
				{
					//提取相对位置
					finalPos = Motion_Compute.Vector3Conversion((string)data_row[5].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFPOS", row_id) + "，相对位置信息填写有错误！");
						}
						return false;
					}
					//提取相对角度
					finalEuler = Motion_Compute.Vector3Conversion((string)data_row[6].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFEULER", row_id) + "，相对角度信息填写有错误！");
						}
						return false;
					}
					GameObject emptyRefer = new GameObject();
					emptyRefer.name = "ObjPut_empty_Refer-" + row_id;
					emptyRefer.transform.parent = referTrans;
					emptyRefer.transform.localPosition = finalPos;
					emptyRefer.transform.localEulerAngles = finalEuler;
					finalPos = emptyRefer.transform.position;
					finalEuler = emptyRefer.transform.eulerAngles;
					emptyRefer.transform.parent = null;
					GameObject.DestroyImmediate(emptyRefer);
				}
				else
				{
					if (Motion_Data.isEditor)
					{
						Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFEULER", row_id) + "，相对位置或角度信息填写有错误！");
					}
					return false;
				}
			}
			else
			{
				if (!MotionPlatformData.toolsManager.ToolsCenter.ContainsKey(objName))
				{
					if (Motion_Data.isEditor)
					{
						Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFGROUP", row_id) +
							"，Group号对应的Group表第一个物体在Tools.xls工具信息中找不到，请确认！");
					}
					return false;
				}
				else
				{
					finalPos = MotionPlatformData.toolsManager.ToolsCenter[objName].Position;
					finalEuler = MotionPlatformData.toolsManager.ToolsCenter[objName].EulerAngle;
				}
			}
			//自定义速度提取
			float moveSpeed = MotionPlatformData.toolMoveSpeed;
			if (data_row.Table.Columns.Count > 7)
			{
				if ((string)data_row[7].ToString() != "")
				{
					moveSpeed = Motion_Compute.FloatConversion((string)data_row[7].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFSPEED", row_id) + "，自定义速度填写有错误！");
						}
						return false;
					}
				}
			}
			//自定义安全高度
			float safeHeight = MotionPlatformData.safeHeight;
			if (data_row.Table.Columns.Count > 8)
			{
				if ((string)data_row[8].ToString() != "")
				{
					safeHeight = Motion_Compute.FloatConversion((string)data_row[8].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "BFHEIGHT", row_id) + "，自定义安全高度填写有错误！");
						}
						return false;
					}
				}
			}

			//开始生成类数据
			IList<IMotion> tempMotionList = new List<IMotion>();
			//首先上升到安全高度
			//New Class，世界坐标移动
			BasicMotion _simpleMotion = new BasicMotion();
			_simpleMotion.State = CurrentState.Active;
			_simpleMotion.CurrentMotion = MotionType.WorldMove;
			_simpleMotion.StartPos = firstObj.position;
			_simpleMotion.StartEurler = firstObj.eulerAngles;
			_simpleMotion.ParentTrans = firstObj;
			_simpleMotion.ListCopy(childList, parentList);
			//如果部件摆放的safeHeight对应的轴要改，修改这个参数
			Vector3 motionVec = new Vector3(0f, safeHeight - _simpleMotion.StartPos.y, 0f);
			_simpleMotion.EndPos = new Vector3(_simpleMotion.StartPos.x, safeHeight, _simpleMotion.StartPos.z);
			_simpleMotion.EndEurler = _simpleMotion.StartEurler;
			if (motionVec.magnitude == 0f)
			{
				_simpleMotion.StandardTime = 0.05f;
				_simpleMotion.SpeedVector = new Vector3(0f, 0f, 0f);
			}
			else
			{
				_simpleMotion.StandardTime = motionVec.magnitude / moveSpeed;
				_simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime;
			}
			_simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate;
			tempMotionList.Add(_simpleMotion);

			//New Class---任意移动过度到目标位置上方
			BasicMotion _simpleMotion2 = new BasicMotion();
			_simpleMotion2.State = CurrentState.Future;
			_simpleMotion2.CurrentMotion = MotionType.RandomMotion;
			_simpleMotion2.StartPos = _simpleMotion.EndPos;
			_simpleMotion2.StartEurler = _simpleMotion.EndEurler;
			_simpleMotion2.ParentTrans = firstObj;
			_simpleMotion2.ListCopy(childList, parentList);
			_simpleMotion2.EndPos = new Vector3(finalPos.x, safeHeight, finalPos.z);
			_simpleMotion2.EndEurler = finalEuler;
			motionVec = _simpleMotion2.EndPos - _simpleMotion2.StartPos;
			float moveTime = 0;
			float rotateTime = 0;
			moveTime = motionVec.magnitude / moveSpeed;
			Vector3 angleDiff = Motion_Compute.GetAngleDiff(_simpleMotion2.StartEurler, ref _simpleMotion2.EndEurler);
			rotateTime = Vector3.Angle(_simpleMotion2.StartEurler, _simpleMotion2.EndEurler) / MotionPlatformData.toolRotateSpeed;
			if (moveTime == 0 && rotateTime == 0)
			{
				_simpleMotion2.StandardTime = 0.05f;
				_simpleMotion2.SpeedVector = Vector3.zero;
				_simpleMotion2.AngleVector = Vector3.zero;
			}
			else if (moveTime > rotateTime)
			{
				_simpleMotion2.StandardTime = moveTime;
				_simpleMotion2.SpeedVector = motionVec / moveTime;
				_simpleMotion2.AngleVector = angleDiff / moveTime;
			}
			else
			{
				_simpleMotion2.StandardTime = rotateTime;
				_simpleMotion2.SpeedVector = motionVec / rotateTime;
				_simpleMotion2.AngleVector = angleDiff / rotateTime;
			}
			_simpleMotion2.EndTime = _simpleMotion2.StandardTime / _simpleMotion2.SpeedRate;
			tempMotionList.Add(_simpleMotion2);

			//New Class，下移到目标位置
			BasicMotion _simpleMotion3 = new BasicMotion();
			_simpleMotion3.State = CurrentState.Future;
			_simpleMotion3.CurrentMotion = MotionType.WorldMove;
			_simpleMotion3.StartPos = _simpleMotion2.EndPos;
			_simpleMotion3.StartEurler = _simpleMotion2.EndEurler;
			_simpleMotion3.ParentTrans = firstObj;
			_simpleMotion3.ListCopy(childList, parentList);
			_simpleMotion3.EndPos = finalPos;
			_simpleMotion3.EndEurler = finalEuler;
			motionVec = _simpleMotion3.EndPos - _simpleMotion3.StartPos;
			if (motionVec.magnitude == 0f)
			{
				_simpleMotion3.StandardTime = 0.05f;
				_simpleMotion3.SpeedVector = new Vector3(0f, 0f, 0f);
			}
			else
			{
				_simpleMotion3.StandardTime = motionVec.magnitude / moveSpeed;
				_simpleMotion3.SpeedVector = motionVec / _simpleMotion3.StandardTime;
			}
			_simpleMotion3.EndTime = _simpleMotion3.StandardTime / _simpleMotion3.SpeedRate;
			tempMotionList.Add(_simpleMotion3);
			complex_motion_list.Add(tempMotionList);

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				GameObject emptyAuto = new GameObject("bai_fang_empty-" + row_id);
				emptyAuto.transform.position = firstObj.position;
				emptyAuto.transform.eulerAngles = firstObj.eulerAngles;
				emptyAuto.transform.parent = referTrans;
				autoAssembleContents[5] = emptyAuto.transform.localPosition.x + "," + emptyAuto.transform.localPosition.y + "," + emptyAuto.transform.localPosition.z;
				autoAssembleContents[6] = emptyAuto.transform.localEulerAngles.x + "," + emptyAuto.transform.localEulerAngles.y + "," + emptyAuto.transform.localEulerAngles.z;
				emptyAuto.transform.parent = null;
				GameObject.Destroy(emptyAuto);

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}

	/// <summary>
	/// 螺钉拧松或拧紧；
	/// </summary>
	public class Motion_Program_NingSong : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			Transform firstObj = null;
			Transform firstObjParent = null;
			List<Transform> parentList = new List<Transform>();
			List<Transform> childList = new List<Transform>();
			Transform screwTrans = null;
			Transform screwTransParent = null;
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSGROUP", row_id) + "，螺钉拧松运动Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSGROUP", row_id) + "，螺钉拧松运动Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			objName = (string)group_table.Rows[0][groupColumn].ToString();
			try
			{
				firstObj = GameObject.Find(objName).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSGROUP", row_id) + "，螺钉拧松运动Group第一个物体填写错误，" + objName + "该物体在场景中不存在！");
				}
				return false;
			}
			firstObjParent = firstObj.parent;
			for (int i = 1; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				Transform tempTrans = null;
				try
				{
					tempTrans = GameObject.Find(objName).transform;
				}
				catch
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				childList.Add(tempTrans);
				parentList.Add(tempTrans.parent);
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}
			//被拧物体
			try
			{
				screwTrans = GameObject.Find((string)data_row[4].ToString()).transform;
				screwTransParent = screwTrans.parent;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSREFER", row_id) + "，被拧物体填写有错误！");
				}
				return false;
			}
			//拧的次数
			int twistTimes = Motion_Compute.IntConversion((string)data_row[5].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSTIMES", row_id) + "，拧的次数填写有错误！");
				}
				return false;
			}
			//扳手到螺钉距离
			Vector3 disNSVec = Motion_Compute.Vector3Conversion((string)data_row[6].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSDIS", row_id) + "，拧的距离填写有错误！");
				}
				return false;
			}
			float disNS = disNSVec.magnitude;
			//旋转轴
			Vector3 rotateAxis = Motion_Compute.Vector3Conversion((string)data_row[7].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSAXIS", row_id) + "，拧的旋转轴填写有错误！");
				}
				return false;
			}
			//拧的角度大小
			float twistDegree = Motion_Compute.FloatConversion((string)data_row[8].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSDEGREE", row_id) + "，拧的旋转轴填写有错误！");
				}
				return false;
			}
			//移动速度
			float moveSpeed = MotionPlatformData.toolMoveSpeed;
			if (data_row.Table.Columns.Count > 9)
			{
				if ((string)data_row[9].ToString() != "")
				{
					moveSpeed = Motion_Compute.FloatConversion((string)data_row[9].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSSPEED", row_id) + "，自定义速度填写有错误！");
						}
						return false;
					}
				}
			}
			//扳手移出的微小距离
			float wrenchBackDis = MotionPlatformData.wrenchBackDis;
			if (data_row.Table.Columns.Count > 10)
			{
				if ((string)data_row[10].ToString() != "")
				{
					wrenchBackDis = Motion_Compute.FloatConversion((string)data_row[10].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSWREHCHDIS", row_id) + "，自定义扳手回退距离填写有错误！");
						}
						return false;
					}
				}
			}

			//扳手移进时的坐标轴，如果要通用化，请修改这里
			Vector3 moveVecUnit = new Vector3(-1.0f, 0f, 0f);
			if (data_row.Table.Columns.Count > 11)
			{
				if ((string)data_row[11].ToString() != "")
				{
					moveVecUnit = Motion_Compute.Vector3Conversion((string)data_row[11].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSBANSHOU", row_id) + "，自定义扳手坐标轴填写有错误！");
						}
						return false;
					}
				}
			}

			//参考空物体
			GameObject emptyRefer = new GameObject();
			emptyRefer.name = "NingSong_empty-" + row_id;
			//开始生成类数据
			IList<IMotion> tempMotionList = new List<IMotion>();
			//首次移进  New---Class
			BasicMotion _simpleMotion = new BasicMotion();
			_simpleMotion.State = CurrentState.Active;
			_simpleMotion.CurrentMotion = MotionType.ProgramMove;
			_simpleMotion.StartPos = firstObj.position;
			_simpleMotion.StartEurler = firstObj.eulerAngles;
			emptyRefer.transform.position = firstObj.position;
			emptyRefer.transform.eulerAngles = firstObj.eulerAngles;
			_simpleMotion.ParentTrans = firstObj;
			_simpleMotion.ListCopy(childList, parentList);


			//扳手拧一圈时移动的距离
			float screwBack = (twistDegree / 30f) * MotionPlatformData.screwBackRate;
			if (data_row.Table.Columns.Count > 12)
			{
				if ((string)data_row[12].ToString() != "")
				{
					screwBack = Motion_Compute.Vector3Conversion((string)data_row[12].ToString(), ref isRight).magnitude / twistTimes;
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "NSCUSTOMDIS", row_id) + "，自定义每次拧紧拧松距离填写有错误！");
						}
						return false;
					}
				}
			}
			Vector3 motionVec = moveVecUnit * disNS;
			emptyRefer.transform.Translate(motionVec, Space.Self);
			_simpleMotion.EndPos = emptyRefer.transform.position;
			_simpleMotion.EndEurler = emptyRefer.transform.eulerAngles;
			_simpleMotion.StandardTime = motionVec.magnitude / moveSpeed;
			_simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime;
			_simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate;
			tempMotionList.Add(_simpleMotion);

			for (int i = 0; i < twistTimes; i++)
			{
				//拧  New---Class
				BasicMotion _simpleMotion2 = new BasicMotion();
				_simpleMotion2.State = CurrentState.Future;
				_simpleMotion2.CurrentMotion = MotionType.MoveRotateSingle;
				_simpleMotion2.ParentTrans = screwTrans;
				_simpleMotion2.ListCopy(childList, parentList);
				_simpleMotion2.ChildList.Add(firstObj);
				_simpleMotion2.ParentList.Add(firstObjParent);
				_simpleMotion2.ChildList.Add(screwTrans);
				_simpleMotion2.ParentList.Add(screwTransParent);
				GameObject emptyObj = new GameObject();
				emptyObj.name = "move-rotate_empty-" + row_id + "-" + i.ToString();
				emptyObj.transform.position = screwTrans.position;
				emptyObj.transform.eulerAngles = screwTrans.eulerAngles;
				//将emptyRefer当做扳手用于后面过程定位
				emptyRefer.transform.parent = emptyObj.transform;
				_simpleMotion2.StartPos = screwTrans.position;
				_simpleMotion2.StartEurler = screwTrans.eulerAngles;
				_simpleMotion2.RotateAxis = rotateAxis.normalized;
				_simpleMotion2.RotateSpeed = MotionPlatformData.wrenchSpeed;
				_simpleMotion2.StandardTime = twistDegree / _simpleMotion2.RotateSpeed;
				motionVec = -rotateAxis * screwBack;
				emptyObj.transform.Translate(motionVec, Space.Self);
				motionVec = _simpleMotion2.ParentTrans.TransformDirection(motionVec).normalized * screwBack;
				_simpleMotion2.SpeedVector = motionVec / _simpleMotion2.StandardTime;
				_simpleMotion2.EndPos = emptyObj.transform.position;
				emptyObj.transform.Rotate(rotateAxis * twistDegree, Space.Self);
				_simpleMotion2.EndEurler = emptyObj.transform.eulerAngles;
				emptyRefer.transform.parent = null;
				emptyObj.transform.position = _simpleMotion2.StartPos;
				emptyObj.transform.eulerAngles = _simpleMotion2.StartEurler;
				_simpleMotion2.EmptyObj = emptyObj;
				_simpleMotion2.EndTime = _simpleMotion2.StandardTime / _simpleMotion2.SpeedRate;
				tempMotionList.Add(_simpleMotion2);
				//中间循环动作
				if (twistTimes - i > 1)
				{
					//扳手退出很小的距离  New---Class
					BasicMotion _simpleMotion3 = new BasicMotion();
					_simpleMotion3.State = CurrentState.Future;
					_simpleMotion3.CurrentMotion = MotionType.ProgramMove;
					_simpleMotion3.ParentTrans = firstObj;
					_simpleMotion3.ListCopy(childList, parentList);
					_simpleMotion3.StartPos = emptyRefer.transform.position;
					_simpleMotion3.StartEurler = emptyRefer.transform.eulerAngles;
					motionVec = -moveVecUnit * wrenchBackDis / 3;
					emptyRefer.transform.Translate(motionVec, Space.Self);
					_simpleMotion3.EndPos = emptyRefer.transform.position;
					_simpleMotion3.EndEurler = emptyRefer.transform.eulerAngles;
					_simpleMotion3.StandardTime = motionVec.magnitude / moveSpeed;
					_simpleMotion3.SpeedVector = motionVec / _simpleMotion3.StandardTime;
					_simpleMotion3.EndTime = _simpleMotion3.StandardTime / _simpleMotion3.SpeedRate;
					tempMotionList.Add(_simpleMotion3);

					//扳手回转  New---Class
					BasicMotion _simpleMotion4 = new BasicMotion();
					_simpleMotion4.State = CurrentState.Future;
					_simpleMotion4.CurrentMotion = MotionType.RotateOnly;
					_simpleMotion4.ParentTrans = firstObj;
					_simpleMotion4.ListCopy(childList, parentList);
					_simpleMotion4.StartPos = emptyRefer.transform.position;
					_simpleMotion4.StartEurler = emptyRefer.transform.eulerAngles;
					_simpleMotion4.RotateCenter = _simpleMotion4.ParentTrans.position;
					_simpleMotion4.RotateAxis = screwTrans.TransformDirection(-rotateAxis.normalized).normalized;
					_simpleMotion4.RotateSpeed = MotionPlatformData.wrenchSpeed * 4f;
					_simpleMotion4.StandardTime = twistDegree / _simpleMotion4.RotateSpeed;
					emptyRefer.transform.RotateAround(_simpleMotion4.RotateCenter, _simpleMotion4.RotateAxis, twistDegree);
					_simpleMotion4.EndPos = emptyRefer.transform.position;
					_simpleMotion4.EndEurler = emptyRefer.transform.eulerAngles;
					_simpleMotion4.EndTime = _simpleMotion4.StandardTime / _simpleMotion4.SpeedRate;
					tempMotionList.Add(_simpleMotion4);

					//扳手再次进入  New---Class
					BasicMotion _simpleMotion5 = new BasicMotion();
					_simpleMotion5.State = CurrentState.Future;
					_simpleMotion5.CurrentMotion = MotionType.ProgramMove;
					_simpleMotion5.ParentTrans = firstObj;
					_simpleMotion5.ListCopy(childList, parentList);
					_simpleMotion5.StartPos = emptyRefer.transform.position;
					_simpleMotion5.StartEurler = emptyRefer.transform.eulerAngles;
					motionVec = moveVecUnit * wrenchBackDis / 3;
					emptyRefer.transform.Translate(motionVec, Space.Self);
					_simpleMotion5.EndPos = emptyRefer.transform.position;
					_simpleMotion5.EndEurler = emptyRefer.transform.eulerAngles;
					_simpleMotion5.StandardTime = motionVec.magnitude / moveSpeed;
					_simpleMotion5.SpeedVector = motionVec / _simpleMotion5.StandardTime;
					_simpleMotion5.EndTime = _simpleMotion5.StandardTime / _simpleMotion5.SpeedRate;
					tempMotionList.Add(_simpleMotion5);
				}
			}
			//最后退出  New---Class
			BasicMotion _simpleMotion6 = new BasicMotion();
			_simpleMotion6.State = CurrentState.Future;
			_simpleMotion6.CurrentMotion = MotionType.ProgramMove;
			_simpleMotion6.StartPos = emptyRefer.transform.position;
			_simpleMotion6.StartEurler = emptyRefer.transform.eulerAngles;
			_simpleMotion6.ParentTrans = firstObj;
			_simpleMotion6.ListCopy(childList, parentList);
			motionVec = -moveVecUnit * disNS;
			emptyRefer.transform.Translate(motionVec, Space.Self);
			_simpleMotion6.EndPos = emptyRefer.transform.position;
			_simpleMotion6.EndEurler = emptyRefer.transform.eulerAngles;
			_simpleMotion6.StandardTime = motionVec.magnitude / moveSpeed;
			_simpleMotion6.SpeedVector = motionVec / _simpleMotion6.StandardTime;
			_simpleMotion6.EndTime = _simpleMotion6.StandardTime / _simpleMotion6.SpeedRate;
			tempMotionList.Add(_simpleMotion6);
			complex_motion_list.Add(tempMotionList);
			emptyRefer.transform.parent = null;
			GameObject.DestroyImmediate(emptyRefer);

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				Vector3 autoVec = -rotateAxis;
				autoAssembleContents[7] = autoVec.x + "," + autoVec.y + "," + autoVec.z;

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}

	/// <summary>
	/// 螺钉拧出或拧进；
	/// </summary>
	public class Motion_Program_NingChu : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			Transform firstObj = null;
			Transform firstObjParent = null;
			List<Transform> parentList = new List<Transform>();
			List<Transform> childList = new List<Transform>();
			Transform screwTrans = null;
			Transform screwTransParent = null;
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCGROUP", row_id) + "，螺钉拧出运动Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCGROUP", row_id) + "，螺钉拧出运动Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			objName = (string)group_table.Rows[0][groupColumn].ToString();
			try
			{
				firstObj = GameObject.Find(objName).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCGROUP", row_id) + "，螺钉拧出运动Group第一个物体填写错误，" + objName + "该物体在场景中不存在！");
				}
				return false;
			}
			firstObjParent = firstObj.parent;
			for (int i = 1; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				Transform tempTrans = null;
				try
				{
					tempTrans = GameObject.Find(objName).transform;
				}
				catch
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				childList.Add(tempTrans);
				parentList.Add(tempTrans.parent);
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}
			//被拧物体
			try
			{
				screwTrans = GameObject.Find((string)data_row[4].ToString()).transform;
				screwTransParent = screwTrans.parent;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCREFER", row_id) + "，被拧物体填写有错误！");
				}
				return false;
			}
			//扳手到螺钉距离
			Vector3 disNCVec = Motion_Compute.Vector3Conversion((string)data_row[5].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCDIS", row_id) + "，拧的距离填写有错误！");
				}
				return false;
			}
			float disNC = disNCVec.magnitude;
			//旋转轴
			Vector3 rotateAxis = Motion_Compute.Vector3Conversion((string)data_row[6].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCAXIS", row_id) + "，拧的旋转轴填写有错误！");
				}
				return false;
			}
			//螺钉拧出的距离
			Vector3 disNCLVec = Motion_Compute.Vector3Conversion((string)data_row[7].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCLDIS", row_id) + "，拧出来的距离填写有错误！");
				}
				return false;
			}
			float disNCL = disNCLVec.magnitude;
			//移动速度
			float moveSpeed = MotionPlatformData.toolMoveSpeed;
			if (data_row.Table.Columns.Count > 8)
			{
				if ((string)data_row[8].ToString() != "")
				{
					moveSpeed = Motion_Compute.FloatConversion((string)data_row[8].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCSPEED", row_id) + "，自定义速度填写有错误！");
						}
						return false;
					}
				}
			}
			//扳手移进时的坐标轴，如果要通用化，请修改这里
			Vector3 moveVecUnit = new Vector3(0f, -1.0f, 0f);
			if (data_row.Table.Columns.Count > 9)
			{
				if ((string)data_row[9].ToString() != "")
				{
					moveVecUnit = Motion_Compute.Vector3Conversion((string)data_row[9].ToString(), ref isRight);
					if (!isRight)
					{
						if (Motion_Data.isEditor)
						{
							Debug.LogError(ErrorLocation.Locate("PROGRAM", "NCBANSHOU", row_id) + "，自定义扳手坐标轴填写有错误！");
						}
						return false;
					}
				}
			}


			//参考空物体
			GameObject emptyRefer = new GameObject();
			emptyRefer.name = "NingChu_empty-" + row_id;
			//开始生成类数据
			IList<IMotion> tempMotionList = new List<IMotion>();
			//首次移进  New---Class
			BasicMotion _simpleMotion = new BasicMotion();
			_simpleMotion.State = CurrentState.Active;
			_simpleMotion.CurrentMotion = MotionType.ProgramMove;
			_simpleMotion.StartPos = firstObj.position;
			_simpleMotion.StartEurler = firstObj.eulerAngles;
			emptyRefer.transform.position = firstObj.position;
			emptyRefer.transform.eulerAngles = firstObj.eulerAngles;
			_simpleMotion.ParentTrans = firstObj;
			_simpleMotion.ListCopy(childList, parentList);


			Vector3 motionVec = moveVecUnit * disNC;
			emptyRefer.transform.Translate(motionVec, Space.Self);
			_simpleMotion.EndPos = emptyRefer.transform.position;
			_simpleMotion.EndEurler = emptyRefer.transform.eulerAngles;
			_simpleMotion.StandardTime = motionVec.magnitude / moveSpeed;
			_simpleMotion.SpeedVector = motionVec / _simpleMotion.StandardTime;
			_simpleMotion.EndTime = _simpleMotion.StandardTime / _simpleMotion.SpeedRate;
			tempMotionList.Add(_simpleMotion);

			//拧出  New---Class
			BasicMotion _simpleMotion2 = new BasicMotion();
			_simpleMotion2.State = CurrentState.Future;
			_simpleMotion2.CurrentMotion = MotionType.MoveRotateSingle;
			_simpleMotion2.ParentTrans = screwTrans;
			_simpleMotion2.ListCopy(childList, parentList);
			_simpleMotion2.ChildList.Add(firstObj);
			_simpleMotion2.ParentList.Add(firstObjParent);
			_simpleMotion2.ChildList.Add(screwTrans);
			_simpleMotion2.ParentList.Add(screwTransParent);
			GameObject emptyObj = new GameObject();
			emptyObj.name = "move-rotate_empty-" + row_id + "-ningchu";
			emptyObj.transform.position = screwTrans.position;
			emptyObj.transform.eulerAngles = screwTrans.eulerAngles;
			//将emptyRefer当做扳手用于后面过程定位
			emptyRefer.transform.parent = emptyObj.transform;
			_simpleMotion2.StartPos = screwTrans.position;
			_simpleMotion2.StartEurler = screwTrans.eulerAngles;
			_simpleMotion2.RotateAxis = rotateAxis;
			float rotateDegree = disNCL / MotionPlatformData.rotateDegreeRate * 360f;
			_simpleMotion2.RotateSpeed = MotionPlatformData.wrenchSpeed * 7;
			_simpleMotion2.StandardTime = rotateDegree / _simpleMotion2.RotateSpeed;
			motionVec = -rotateAxis * disNCL;
			emptyObj.transform.Translate(motionVec, Space.Self);
			motionVec = _simpleMotion2.ParentTrans.TransformDirection(motionVec).normalized * disNCL;
			_simpleMotion2.SpeedVector = motionVec / _simpleMotion2.StandardTime;
			_simpleMotion2.EndPos = emptyObj.transform.position;
			emptyObj.transform.Rotate(rotateAxis * rotateDegree, Space.Self);
			_simpleMotion2.EndEurler = emptyObj.transform.eulerAngles;
			emptyRefer.transform.parent = null;
			emptyObj.transform.position = _simpleMotion2.StartPos;
			emptyObj.transform.eulerAngles = _simpleMotion2.StartEurler;
			_simpleMotion2.EmptyObj = emptyObj;
			_simpleMotion2.EndTime = _simpleMotion2.StandardTime / _simpleMotion2.SpeedRate;
			tempMotionList.Add(_simpleMotion2);
			//最后退出  New---Class
			BasicMotion _simpleMotion6 = new BasicMotion();
			_simpleMotion6.State = CurrentState.Future;
			_simpleMotion6.CurrentMotion = MotionType.ProgramMove;
			_simpleMotion6.StartPos = emptyRefer.transform.position;
			_simpleMotion6.StartEurler = emptyRefer.transform.eulerAngles;
			_simpleMotion6.ParentTrans = firstObj;
			_simpleMotion6.ListCopy(childList, parentList);
			motionVec = -moveVecUnit * disNC;
			emptyRefer.transform.Translate(motionVec, Space.Self);
			_simpleMotion6.EndPos = emptyRefer.transform.position;
			_simpleMotion6.EndEurler = emptyRefer.transform.eulerAngles;
			_simpleMotion6.StandardTime = motionVec.magnitude / moveSpeed;
			_simpleMotion6.SpeedVector = motionVec / _simpleMotion6.StandardTime;
			_simpleMotion6.EndTime = _simpleMotion6.StandardTime / _simpleMotion6.SpeedRate;
			tempMotionList.Add(_simpleMotion6);
			complex_motion_list.Add(tempMotionList);
			emptyRefer.transform.parent = null;
			GameObject.DestroyImmediate(emptyRefer);

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				Vector3 autoVec = -rotateAxis;
				autoAssembleContents[6] = autoVec.x + "," + autoVec.y + "," + autoVec.z;

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}

	/// <summary>
	/// 工具瞬间摆放；
	/// </summary>
	public class Motion_Program_ToolPut : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			BasicMotion simpleMotion = new BasicMotion();
			simpleMotion.CurrentMotion = MotionType.SetTool;
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TPGROUP", row_id) + "，工具摆放运动Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TPGROUP", row_id) + "，工具摆放运动Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			try
			{
				objName = (string)group_table.Rows[0][groupColumn].ToString();
				simpleMotion.ParentTrans = GameObject.Find(objName).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TPGROUP", row_id) + "，Group号对应的Group表填写有错误，物体" + objName + "在场景中找不到！");
				}
				return false;
			}

			//任意部件移动信息提取
			Vector3 finalPos = new Vector3(0f, 0f, 0f);
			Vector3 finalEuler = new Vector3(0f, 0f, 0f);
			if (!MotionPlatformData.toolsManager.ToolsCenter.ContainsKey(objName))
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TPGROUP", row_id) +
						"，Group号对应的Group表第一个物体在Tools.xls工具信息中找不到，请确认！");
				}
				return false;
			}
			else
			{
				finalPos = MotionPlatformData.toolsManager.ToolsCenter[objName].Position;
				finalEuler = MotionPlatformData.toolsManager.ToolsCenter[objName].EulerAngle;
			}

			//起始信息记录
			simpleMotion.StartPos = simpleMotion.ParentTrans.position;
			simpleMotion.StartEurler = simpleMotion.ParentTrans.eulerAngles;
			//终止位置获取
			simpleMotion.EndPos = finalPos;
			simpleMotion.EndEurler = finalEuler;
			simpleMotion.StandardTime = 0.05f;
			simpleMotion.EndTime = 0.05f;
			motion_list.Add(simpleMotion);

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				/* ********************************************************
				 * 1.装配运动为SetToolPos：先记录位置,再保存信息存储工作表名
				 * *******************************************************/
				autoAssembleContents[2] = "SetToolPos";
				autoAssembleContents[5] = "ToolPut";

				List<Transform> listTrans = new List<Transform>();
				string objName1 = "";
				int groupColumn1 = Motion_Compute.IntConversion(autoAssembleContents[3].ToString(), ref isRight) + 1;
				try
				{
					objName1 = (string)group_table.Rows[0][groupColumn1].ToString();
					listTrans.Add(GameObject.Find(objName1).transform);
					for (int mm = 1; mm < group_table.Rows.Count; mm++)
					{
						objName1 = (string)group_table.Rows[mm][groupColumn1].ToString();
						if (objName1 == "")
							break;
						listTrans.Add(GameObject.Find(objName1).transform);
					}
				}
				catch
				{
					if (Motion_Data.isEditor)
					{
						Debug.LogError(ErrorLocation.Locate("EXCEL", "GROUP", row_id) + "，Group号对应的Group表填写有错误！");
					}
					return false;
				}

				string sheet_name_tmp = MotionPlatformData.taskName + "_" + MotionPlatformData.excelName + "_Program_" + autoAssembleContents[1];
				Positions.recordLocations(sheet_name_tmp, "Z", listTrans);

				autoAssembleContents[4] = sheet_name_tmp;

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}

	/// <summary>
	/// 螺钉批量摆放；
	/// </summary>
	public class Motion_Program_LuoDingPut : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{

			BasicMotion simpleMotion = new BasicMotion();
			simpleMotion.CurrentMotion = MotionType.SetLuoDingPos;
			bool isRight = true;
			List<Transform> parentList = new List<Transform>();
			List<Transform> childList = new List<Transform>();
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPGROUP", row_id) + "，螺钉自动摆放运动Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPGROUP", row_id) + "，螺钉自动摆放运动Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			objName = (string)group_table.Rows[0][groupColumn].ToString();
			try
			{
				simpleMotion.ParentTrans = GameObject.Find(objName).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPGROUP", row_id) + "，螺钉自动摆放运动Group第一个物体填写错误，" + objName + "该物体在场景中不存在！");
				}
				return false;
			}
			for (int i = 1; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				Transform tempTrans = null;
				try
				{
					tempTrans = GameObject.Find(objName).transform;
				}
				catch
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				childList.Add(tempTrans);
				parentList.Add(tempTrans.parent);
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}

			//终止位置获取
			GameObject empty = new GameObject();
			empty.name = "luoding_put_empty-" + row_id;
			Transform refTrans;
			try
			{
				refTrans = GameObject.Find((string)data_row[4].ToString()).transform;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPREFER", row_id) + "，参考物体填写错误！");
				}
				return false;
			}
			simpleMotion.EndPos = Motion_Compute.Vector3Conversion((string)data_row[5].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPPOSITION", row_id) + "，参考位置填写错误！");
				}
				return false;
			}
			simpleMotion.EndEurler = Motion_Compute.Vector3Conversion((string)data_row[6].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPEURLER", row_id) + "，参考角度填写错误！");
				}
				return false;
			}
			empty.transform.parent = refTrans;
			empty.transform.localPosition = simpleMotion.EndPos;
			empty.transform.localEulerAngles = simpleMotion.EndEurler;
			simpleMotion.EndPos = empty.transform.position;
			simpleMotion.EndEurler = empty.transform.eulerAngles;
			empty.transform.parent = null;


			//间距转化
			bool isWorld = true;
			if ((string)data_row[7].ToString().ToLower() == "true")
			{
				isWorld = true;
			}
			else
			{
				isWorld = false;
			}

			//间距读取
			Vector3 intervalVec = Motion_Compute.Vector3Conversion((string)data_row[8].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "LDPINTERVAL", row_id) + "，螺钉间距格式填写错误！");
				}
				return false;
			}

			if (isWorld)
			{
				simpleMotion.SpeedVector = intervalVec;
			}
			else
			{
				//从相对角度转化到世界坐标
				simpleMotion.SpeedVector = empty.transform.TransformPoint(intervalVec) - empty.transform.position;
			}
			GameObject.DestroyImmediate(empty);
			//起始信息记录
			simpleMotion.StartPos = simpleMotion.ParentTrans.position;
			simpleMotion.StartEurler = simpleMotion.ParentTrans.eulerAngles;
			simpleMotion.ListCopy(childList, parentList);
			//终止位置获取
			simpleMotion.StandardTime = 0.05f;
			simpleMotion.EndTime = 0.05f;
			motion_list.Add(simpleMotion);

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				/* ********************************************************
				 * 1.装配运动为SetToolPos：先记录位置,再保存信息存储工作表名
				 * *******************************************************/
				autoAssembleContents[2] = "SetToolPos";

				string sheet_name_tmp = MotionPlatformData.taskName + "_" + MotionPlatformData.excelName + "_Program_" + autoAssembleContents[1];
				Positions.recordLocations(sheet_name_tmp, "Z");

				autoAssembleContents[4] = sheet_name_tmp;

				for (int k = 5; k < autoAssembleContents.Length; k++)
				{
					autoAssembleContents[k] = "";
				}

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}


	/// <summary>
	/// 透明设置；
	/// </summary>
	public class Motion_Program_ToolTransparent : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			Hashtable cameraHashTable = new Hashtable();

			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.ToolTransparent;
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TTGROUP", row_id) + "，透明Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TTGROUP", row_id) + "，透明Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			string objNames = "";
			for (int i = 0; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				GameObject tempObj = GameObject.Find(objName);
				if (tempObj == null)
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				else
				{
					if (objNames == "")
					{
						objNames = objName;
					}
					else
					{
						objNames += ("," + objName);
					}
					simpleMotion.my_choose.Add(tempObj);
				}
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TTGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}

			//透明度获取
			simpleMotion.transparent_percent = Motion_Compute.FloatConversion((string)data_row[4].ToString(), ref isRight);
			if (simpleMotion.transparent_percent < 0f || simpleMotion.transparent_percent > 1f)
			{
				isRight = false;
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TTTRANSPARENT", row_id) + "，部件透明度填写错误！");
				}
				return false;
			}
			cameraHashTable.Add("Transparent_Percent", simpleMotion.transparent_percent);

			//透明度是否跟随generalMotion一起消失
			simpleMotion.generalMotion_Disappear = Motion_Compute.BoolConversion((string)data_row[5].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TTDISAPPEAR", row_id) + "，部件透明度是否跟随generalMotions消失填写错误！");
				}
				return false;
			}
			if (simpleMotion.generalMotion_Disappear)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("Transparent");
				if (!MotionPlatformData.st_Transparent && _t != null)
				{
					MotionPlatformData.st_Transparent = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}

				if (MotionPlatformData.st_Transparent && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("AfterMotionAdd");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { simpleMotion.my_choose };
					methodInfo.Invoke(MotionPlatformData.st_Transparent, flag, Type.DefaultBinder, para, null);
				}

				simpleMotion.StandardTime = 0.05f;
				simpleMotion.EndTime = simpleMotion.StandardTime;
				motion_list.Add((IMotion)simpleMotion);

				cameraHashTable.Add("isTransparent", !simpleMotion.generalMotion_Disappear);
				//记录相机的视野状态
				if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
				{
					_t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
					if (!MotionPlatformData.st_ReflectionManager && _t != null)
					{
						MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
					}
					string[] tmpStr = objNames.Split(',');
					for (int i = 0; i < tmpStr.Length; i++)
					{
						if (MotionPlatformData.st_ReflectionManager && _t != null)
						{
							MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
							BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
							object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_Transparent", tmpStr[i], cameraHashTable };
							methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
						}
					}

				}
				return true;
			}

			//持续时间
			simpleMotion.StandardTime = Motion_Compute.FloatConversion((string)data_row[6].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TTTIME", row_id) + "，部件透明显示时间填写错误！");
				}
				return false;
			}

			//持续时间后是否消失
			simpleMotion.time_Disappear = Motion_Compute.BoolConversion((string)data_row[7].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "TTTIMEDISAPPEAR", row_id) + "，部件透明是否在指定时间后消失填写错误！");
				}
				return false;
			}

			simpleMotion.EndTime = simpleMotion.StandardTime / simpleMotion.SpeedRate;
			motion_list.Add(simpleMotion);

			cameraHashTable.Add("isTransparent", !simpleMotion.time_Disappear);
			//记录相机的视野状态
			if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
				if (!MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}
				string[] tmpStr = objNames.Split(',');
				for (int i = 0; i < tmpStr.Length; i++)
				{
					if (MotionPlatformData.st_ReflectionManager && _t != null)
					{
						MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
						BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
						object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_Transparent", tmpStr[i], cameraHashTable };
						methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
					}
				}
			}

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				if (autoAssembleContents[5].ToUpper() == "FALSE")
				{
					if (autoAssembleContents[7].ToUpper() == "FALSE")
					{
						autoAssembleContents[7] = "true";
					}
					else if (autoAssembleContents[7].ToUpper() == "TRUE")
					{

					}
				}

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}

	/// <summary>
	/// 高亮设置；
	/// </summary>
	public class Motion_Program_ToolHighlighting : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			Hashtable cameraHashTable = new Hashtable();

			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.ToolHighlighting;
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "THGROUP", row_id) + "，部件高亮Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "THGROUP", row_id) + "，部件高亮Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			string objNames = "";
			for (int i = 0; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				GameObject tempObj = GameObject.Find(objName);
				if (tempObj == null)
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				else
				{
					if (objNames == "")
					{
						objNames = objName;
					}
					else
					{
						objNames += ("," + objName);
					}
					simpleMotion.my_choose.Add(tempObj);
				}
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "THGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}

			//是否高亮
			simpleMotion.isHighlighting = Motion_Compute.BoolConversion((string)data_row[4].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "THHIGHLIGHTING", row_id) + "，部件是否高亮填写错误！");
				}
				return false;
			}

			//高亮是否跟随generalMotion一起消失
			simpleMotion.generalMotion_Disappear = Motion_Compute.BoolConversion((string)data_row[5].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "THDISAPPEAR", row_id) + "，部件高亮是否消失填写错误！");
				}
				return false;
			}
			if (simpleMotion.generalMotion_Disappear)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("HighlightingControl");
				if (!MotionPlatformData.st_HightLighting && _t != null)
				{
					MotionPlatformData.st_HightLighting = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}

				if (MotionPlatformData.st_HightLighting && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("AfterMotionAdd");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { simpleMotion.my_choose };
					methodInfo.Invoke(MotionPlatformData.st_HightLighting, flag, Type.DefaultBinder, para, null);
				}

				simpleMotion.StandardTime = 0.05f;
				simpleMotion.EndTime = simpleMotion.StandardTime;
				motion_list.Add((IMotion)simpleMotion);

				cameraHashTable.Add("isHighLighting", !simpleMotion.generalMotion_Disappear);
				//记录相机的视野状态
				if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
				{
					_t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
					if (!MotionPlatformData.st_ReflectionManager && _t != null)
					{
						MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
					}
					string[] tmpStr = objNames.Split(',');
					for (int i = 0; i < tmpStr.Length; i++)
					{
						if (MotionPlatformData.st_ReflectionManager && _t != null)
						{
							MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
							BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
							object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_HighLighting", tmpStr[i], cameraHashTable };
							methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
						}
					}
				}
				return true;
			}

			//持续时间
			simpleMotion.StandardTime = Motion_Compute.FloatConversion((string)data_row[6].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "THTIME", row_id) + "，部件高亮持续时间填写错误！");
				}
				return false;
			}

			//持续时间后是否消失
			simpleMotion.time_Disappear = Motion_Compute.BoolConversion((string)data_row[7].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "THTIMEDISAPPEAR", row_id) + "，部件高亮是否在指定时间后消失填写错误！");
				}
				return false;
			}

			simpleMotion.EndTime = simpleMotion.StandardTime / simpleMotion.SpeedRate;
			motion_list.Add(simpleMotion);

			cameraHashTable.Add("isHighLighting", !simpleMotion.time_Disappear);
			//记录相机的视野状态
			if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
				if (!MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}
				string[] tmpStr = objNames.Split(',');
				for (int i = 0; i < tmpStr.Length; i++)
				{
					if (MotionPlatformData.st_ReflectionManager && _t != null)
					{
						MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
						BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
						object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_HighLighting", tmpStr[i], cameraHashTable };
						methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
					}
				}
			}

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				if (autoAssembleContents[5].ToUpper() == "FALSE")
				{
					if (autoAssembleContents[7].ToUpper() == "FALSE")
					{
						autoAssembleContents[7] = "true";
					}
					else if (autoAssembleContents[7].ToUpper() == "TRUE")
					{

					}
				}

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}
	}

	/// <summary>
	/// 批量设置部件位置；
	/// </summary>
	public class Motion_Program_SetToolPos : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.SetToolPos;
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "STPGROUP", row_id) + "，设置部件位置Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "STPGROUP", row_id) + "，设置部件位置Group组号超出范围");
				}
				return false;
			}
			//运动物体信息
			string objName = "";
			for (int i = 0; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				GameObject tempObj = GameObject.Find(objName);
				if (tempObj == null)
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				else
				{
					simpleMotion.my_choose.Add(tempObj);
				}
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "STPGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}

			//部件信息存储工作表
			string sheet_name = (string)data_row[4].ToString();
			if (sheet_name != "")
			{
				simpleMotion.sheetName = sheet_name;

				JsonOperator jsonOp = new JsonOperator();
				//位置信息路径
				string locationPath = MotionPlatformData.taskRootPath + MotionPlatformData.taskName + "/";

				if (!File.Exists(locationPath + "C/" + "tmpLocation.json"))
				{
					Debug.LogError(locationPath + "C/" + "tmpLocation.json文件不存在");
					return false;
				}

				DataTable dt = jsonOp.JsonReader(locationPath + "C/" + "tmpLocation.json", simpleMotion.sheetName);
				if (dt == null)
				{
					Debug.LogError(locationPath + "C/" + "tmpLocation.json文件中不存在" + simpleMotion.sheetName);
					return false;
				}

				simpleMotion.toolPos = dt;
			}

			//是否是工具摆放类
			string isToolPut = (string)data_row[5].ToString();
			if (isToolPut == "ToolPut")
			{
				ArrayList my_choose2 = new ArrayList();
				for (int mm = 0; mm < simpleMotion.my_choose.Count; mm++)
				{
					//遍历子物体
					TransformRecursion(((GameObject)simpleMotion.my_choose[mm]).transform, my_choose2);
				}

				simpleMotion.my_choose.Clear();
				for (int mm = 0; mm < my_choose2.Count; mm++)
				{
					simpleMotion.my_choose.Add((GameObject)my_choose2[mm]);
				}
			}

			simpleMotion.StandardTime = 0.05f;
			simpleMotion.EndTime = 0.05f;
			motion_list.Add(simpleMotion);

			//自动装配处理
			if (Motion_Data.IsAutoAssemble)
			{
				//用于记录自动装配信息
				string[] autoAssembleContents = new string[data_row.Table.Columns.Count];
				for (int i = 0; i < data_row.Table.Columns.Count; i++)
				{
					autoAssembleContents[i] = data_row[i].ToString();
				}

				string sheet_name_tmp = MotionPlatformData.taskName + "_" + MotionPlatformData.excelName + "_Program_" + autoAssembleContents[1];
				Positions.recordLocations(sheet_name_tmp, "Z");

				autoAssembleContents[4] = sheet_name_tmp;

				//更新当前行
				Motion_AutoAssemblyAndTime.AutoUpdate(autoAssembleContents, "PROGRAM", 1);
			}

			return true;
		}

		//遍历搜寻子物体；
		private void TransformRecursion(Transform aimTrans, ArrayList al)
		{
			al.Add(aimTrans.gameObject);
			if (aimTrans.childCount > 0)
			{
				foreach (Transform child in aimTrans)
				{
					TransformRecursion(child, al);
				}
			}
		}
	}

	/// <summary>
	/// 播放声音控制；
	/// </summary>
	public class Motion_Program_Music : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{
			Hashtable cameraHashTable = new Hashtable();

			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.MUSIC;
			bool isRight = true;

			//声音文件
			string voice_name = data_row[3].ToString();
			try
			{
				if (FunctionMotion.audioSource == null)
				{
					FunctionMotion.audioSource = GameObject.Find(Motion_Data.MainScriptStr).GetComponent<AudioSource>();
				}
				FunctionMotion.audioSource.clip = (AudioClip)Resources.Load("MP3/" + voice_name);
				simpleMotion.fileName = voice_name;
			}
			catch
			{
				isRight = false;
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MUFILENAME", row_id) + "，声音播放文件名填写错误！");
				}
				return false;
			}
			cameraHashTable.Add("File", simpleMotion.fileName);

			//高亮是否跟随generalMotion一起消失
			simpleMotion.generalMotion_Disappear = Motion_Compute.BoolConversion((string)data_row[4].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MUDISAPPEAR", row_id) + "，声音播放是否消失填写错误！");
				}
				return false;
			}
			FunctionMotion.generalMotionSource = simpleMotion.generalMotion_Disappear;
			if (simpleMotion.generalMotion_Disappear)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("HighlightingControl");
				if (!MotionPlatformData.st_HightLighting && _t != null)
				{
					MotionPlatformData.st_HightLighting = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}

				if (MotionPlatformData.st_HightLighting && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("AfterMotionAdd");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { simpleMotion.my_choose };
					methodInfo.Invoke(MotionPlatformData.st_HightLighting, flag, Type.DefaultBinder, para, null);
				}

				simpleMotion.StandardTime = 0.05f;
				simpleMotion.EndTime = simpleMotion.StandardTime;
				motion_list.Add((IMotion)simpleMotion);

				cameraHashTable.Add("isPlaying", !simpleMotion.generalMotion_Disappear);
				//记录相机的视野状态
				if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
				{
					_t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
					if (!MotionPlatformData.st_ReflectionManager && _t != null)
					{
						MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
					}
					if (MotionPlatformData.st_ReflectionManager && _t != null)
					{
						MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
						BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
						object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_Music", "Music", cameraHashTable };
						methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
					}
				}
				return true;
			}

			//持续时间
			simpleMotion.StandardTime = Motion_Compute.FloatConversion((string)data_row[5].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MUTIME", row_id) + "，声音播放持续时间填写错误！");
				}
				return false;
			}

			//持续时间后是否消失
			simpleMotion.time_Disappear = Motion_Compute.BoolConversion((string)data_row[6].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MUTIMEDISAPPEAR", row_id) + "，声音播放是否在指定时间后消失填写错误！");
				}
				return false;
			}

			simpleMotion.EndTime = simpleMotion.StandardTime / simpleMotion.SpeedRate;
			motion_list.Add((IMotion)simpleMotion);

			cameraHashTable.Add("isPlaying", !simpleMotion.time_Disappear);
			//记录相机的视野状态
			if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
				if (!MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}
				if (MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_Music", "Music", cameraHashTable };
					methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
				}
			}
			return true;
		}
	}

	/// <summary>
	/// 材质变换；
	/// </summary>
	public class Motion_Program_ChangeMats : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{

			Hashtable changeMatsHashTable = new Hashtable();

			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.ChangeMat;

			//变换材质的物体
			string gameobjectName = data_row[3].ToString();
			GameObject obj;
			try
			{
				obj = GameObject.Find(gameobjectName);
				simpleMotion.obj = obj;
			}
			catch
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "CMGAMEOBJECT", row_id) + "，变换材质的物体名填写错误！");
				}
				return false;
			}

			//变换前材质
			simpleMotion.oldMats = new List<Material>();

			string[] strMat1 = data_row[4].ToString().Split('#');
			List<string> tmpList = new List<string>();
			List<int> tmpListInt = new List<int>();
			for (int i = 0; i < strMat1.Length; i++)
			{
				tmpList.Add(strMat1[i]);
			}
			int matCount = 0;
			for (int i = 0; i < obj.renderer.materials.Length; i++)
			{
				string matName = obj.renderer.materials[i].name;
				if (matName.Contains(" (Instance)"))
				{
					matName = matName.Substring(0, matName.Length - 11);
				}
				if (tmpList.Contains(matName))
				{
					simpleMotion.oldMats.Add(obj.renderer.materials[i]);
					tmpListInt.Add(i);
					matCount++;
				}
			}
			if (matCount != strMat1.Length)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "CMOLDMATS", row_id) + "，变换材质的物体变换前的材质名填写错误！");
				}
			}
			string oldMats = obj.renderer.materials[0].name;
			for (int i = 1; i < obj.renderer.materials.Length; i++)
			{
				oldMats += ("," + obj.renderer.materials[i].name);
			}

			changeMatsHashTable.Add("OldMats", oldMats);

			//变换后材质
			simpleMotion.newMats = new List<Material>();

			string[] strMat2 = data_row[5].ToString().Split('#');
			int mat2Count = strMat2.Length;
			Material[] newMaterials = obj.renderer.materials;
			for (int i = 0; i < strMat2.Length; i++)
			{
				if (!Directory.Exists(Application.dataPath + "/Resources/" + EquipmentSettings.CurrentEquipment + "/Materials_Prefab"))
				{
					Debug.LogError(EquipmentSettings.CurrentEquipment + "目录下不存在Materials_Prefab文件夹");
				}
				Material mat = (Material)Resources.Load(EquipmentSettings.CurrentEquipment + "/Materials_Prefab/" + strMat2[i]);
				if (mat == null)
				{
					if (Motion_Data.isEditor)
					{
						Debug.LogError(ErrorLocation.Locate("PROGRAM", "CMNEWMATS", row_id) + "，变换材质的物体变换后的材质名在" + strMat2[i] + EquipmentSettings.CurrentEquipment + "/Materials_Prefab目录下不存在");
					}
				}

				simpleMotion.newMats.Add(mat);
				newMaterials[tmpListInt[i]] = mat;
			}
			if (mat2Count != matCount)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "CMNEWMATS", row_id) + "，变换材质的物体变换后的材质名个数与变换前材质个数不同！");
				}
			}
			string newMats = newMaterials[0].name;
			for (int i = 1; i < newMaterials.Length; i++)
			{
				newMats += ("," + newMaterials[i].name);
			}
			changeMatsHashTable.Add("NewMats", newMats);

			simpleMotion.EndTime = simpleMotion.StandardTime / simpleMotion.SpeedRate;
			motion_list.Add((IMotion)simpleMotion);

			//记录切换材质物体的状态
			if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
				if (!MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}
				if (MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_ChangeMats", gameobjectName, changeMatsHashTable };
					methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
				}
			}
			//装配表生成
			return true;
		}
	}

	/// <summary>
	/// 画线标记；
	/// </summary>
	public class Motion_Program_Mark : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{

			Hashtable markHashTable = new Hashtable();

			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.Mark;
			bool isRight = true;

			//需要画线的物体
			string gameobjectName = data_row[3].ToString();
			GameObject obj;
			try
			{
				obj = GameObject.Find(gameobjectName);
				simpleMotion.obj = obj;
			}
			catch
			{
				isRight = false;
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MKOBJECT", row_id) + "，画线标记物体名填写错误！");
				}
				return false;
			}
			markHashTable.Add("Gamobject", gameobjectName);

			//用于标记的prefab名
			string prefabName = data_row[4].ToString();
			simpleMotion.prefabName = prefabName;
			if (!Directory.Exists(Application.dataPath + "/Resources/" + EquipmentSettings.CurrentEquipment + "/Materials_Prefab"))
			{
				Debug.LogError(Application.dataPath + "/Resources/" + EquipmentSettings.CurrentEquipment + "/" + "目录下不存在Materials_Prefab文件夹");
			}
			try
			{
				simpleMotion.prefab = Resources.Load(EquipmentSettings.CurrentEquipment + "/Materials_Prefab/" + prefabName);
			}
			catch
			{
				Debug.Log(prefabName + "预制件不存在，请拖动预制到该文件夹：" + Application.dataPath + "/Resources/" + EquipmentSettings.CurrentEquipment + "/Materials_Prefab");
			}
			if (simpleMotion.prefab == null)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MKPOS", row_id) + "，标记相对于被标记物体的相对位置错误！");
				}
			}
			markHashTable.Add("Prefab", data_row[4].ToString());

			//相对于被标记物体的相对坐标
			simpleMotion.markPosition = Motion_Compute.Vector3Conversion(data_row[5].ToString(), ref isRight);
			if (!isRight)
			{
				isRight = false;
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MKPOS", row_id) + "，标记相对于被标记物体的相对位置错误！");
				}
			}
			markHashTable.Add("Pos", data_row[5].ToString());

			//相对与被标记物体的相对角度
			simpleMotion.markEulerangle = Motion_Compute.Vector3Conversion(data_row[6].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MKEUL", row_id) + "，标记相对于被标记物体的相对角度错误！");
				}
			}
			markHashTable.Add("Eul", data_row[6].ToString());

			//标记物体的大小
			simpleMotion.markScale = Motion_Compute.Vector3Conversion(data_row[7].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MKSCALE", row_id) + "，标记的大小错误！");
				}
			}
			markHashTable.Add("Scale", data_row[7].ToString());

			//标记物体是否显示
			simpleMotion.markShow = Motion_Compute.BoolConversion(data_row[8].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "MKSHOW", row_id) + "，标记是否显示填写错误！");
				}
			}
			markHashTable.Add("Show", data_row[8].ToString());

			simpleMotion.EndTime = simpleMotion.StandardTime / simpleMotion.SpeedRate;
			motion_list.Add((IMotion)simpleMotion);

			//记录切换材质物体的状态
			if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
				if (!MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}
				if (MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_Mark", gameobjectName + "~" + prefabName, markHashTable };
					methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
				}
			}
			//装配表生成
			return true;
		}
	}

	/// <summary>
	/// 隐藏显示；
	/// </summary>
	public class Motion_Program_HideShow : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{

			Hashtable hideHashTable = new Hashtable();

			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.HideShow;
			bool isRight = true;
			//Group Column
			int groupColumn = Motion_Compute.IntConversion((string)data_row[3].ToString(), ref isRight) + 1;
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "HSGROUP", row_id) + "，隐藏显示Group填写错误！");
				}
				return false;
			}
			if (groupColumn >= group_table.Columns.Count || groupColumn <= 0)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "HSGROUP", row_id) + "，隐藏显示Group组号超出范围");
				}
				return false;
			}

			//是否包含子物体
			bool containsChildren = false;
			if (data_row[5].ToString().ToUpper() == "TRUE")
			{
				containsChildren = true;
			}

			//运动物体信息
			string objName = "";
			for (int i = 0; i < group_table.Rows.Count; i++)
			{
				objName = (string)group_table.Rows[i][groupColumn].ToString();
				if (objName == "")
					break;
				GameObject tempObj = GameObject.Find(objName);
				if (tempObj == null)
				{
					isRight = false;
					Debug.LogError(objName + "，该物体在场景中不存在！");
					continue;
				}
				else
				{
					if (tempObj.renderer == null)
					{
						Debug.LogWarning(objName + "，该物体没有render是空物体，该条信息只是警告，如果其有子物体且您填写了让其隐藏或显示，程序仍会正常运行！");
					}

					//包含子物体
					if (containsChildren)
					{
						List<GameObject> tmpList = new List<GameObject>();
						TransformRecursion(tempObj.transform, tmpList);

						for (int iii = 0; iii < tmpList.Count; iii++)
						{
							simpleMotion.my_choose.Add(tmpList[iii]);
						}
					}
					else
					{
						simpleMotion.my_choose.Add(tempObj);
					}
				}
			}
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "HSGROUP", row_id) + "，Group号对应的Group表填写有错误！");
				}
				return false;
			}

			//标记物体是否显示
			simpleMotion.isHide = Motion_Compute.BoolConversion(data_row[4].ToString(), ref isRight);
			if (!isRight)
			{
				if (Motion_Data.isEditor)
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "HSSHOW", row_id) + "，物体是否隐藏填写错误！");
				}
			}
			hideHashTable.Add("IsHide", simpleMotion.isHide);

			simpleMotion.EndTime = simpleMotion.StandardTime / simpleMotion.SpeedRate;
			motion_list.Add((IMotion)simpleMotion);

			//记录隐藏显示物体的状态
			if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
			{
				Type _t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
				if (!MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}
				for (int i = 0; i < simpleMotion.my_choose.Count; i++)
				{
					if (MotionPlatformData.st_ReflectionManager && _t != null)
					{
						MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
						BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
						object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_HideShow", ((GameObject)simpleMotion.my_choose[i]).name, hideHashTable };
						methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
					}
				}
			}
			//装配表生成
			return true;
		}

		void TransformRecursion(Transform aimTrans, List<GameObject> al)
		{
			if (aimTrans.gameObject.renderer != null)
			{
				al.Add(aimTrans.gameObject);
			}
			if (aimTrans.childCount > 0)
			{
				foreach (Transform child in aimTrans)
				{
					TransformRecursion(child, al);
				}
			}
		}
	}

	/// <summary>
	/// 设置变量值；
	/// </summary>
	public class Motion_Program_SetVariable : IMotionFunctionInfo
	{
		public bool InfoGet(DataRow data_row, string row_id, DataTable group_table, IList<IMotion> motion_list, IList<IList<IMotion>> complex_motion_list)
		{

			FunctionMotion simpleMotion = new FunctionMotion();
			simpleMotion.CurrentMotion = MotionType.SetVariable;
            //bool isRight = true;
			//变量ID
			string tmpVarID = (string)data_row[3].ToString();
			if (!ExpressionManager.IsCreatedVariable(tmpVarID))
			{
				Debug.LogError(ErrorLocation.Locate("PROGRAM", "SETVARID", row_id) + "对应的公式表参数ID填写错误！");
			}
			simpleMotion.varID = tmpVarID;

			//变量值
			string tmpVarValue = (string)data_row[4].ToString();
			if (!(ExpressionManager.GetCurrentType(simpleMotion.varID) == typeof(string)))
			{
				if (!ExpressionManager.IsCreatedExpression("tmpValue")){
					ExpressionManager.CreateExpression("tmpValue", tmpVarValue);
				}
				else{
					ExpressionManager.ChangeExpression("tmpValue", tmpVarValue);
				}
			}
			else{
				if (!ExpressionManager.IsCreated("tmpValue2"))
				{
					ExpressionManager.CreateVariable("tmpValue2", "string", tmpVarValue);
				}
				else
				{
					ExpressionManager.ChangeValue("tmpValue2", tmpVarValue);
				}
			}

			//if (!ExpressionManager.IsCreated("tmpValue"))
			//{
			//    //ExpressionManager.CreateExpression("tmpValue", tmpVarValue);
			//}
			//else
			//{
			//    //ExpressionManager.ChangeExpression("tmpValue", tmpVarValue);
			//}

			float tmpValue = 0;
			int tmpValue2 = 0;
			double tmpValue3 = 0;
			bool tmpValue4 = false;
			string tmpStr4 = "";
			try
			{
				//Debug.Log("tmpValue:" + ExpressionManager.IsCreated("tmpValue") + "," );
				if (!(ExpressionManager.GetCurrentType(simpleMotion.varID) == typeof(string)))
				{
					tmpStr4 = ExpressionManager.GetValue("tmpValue").ToString();
				}
				else {
					tmpStr4 = ExpressionManager.GetValue("tmpValue2").ToString();
				}
			}
			catch(Exception e) {
				Debug.Log(e.Message);
			}
			//如果是float类型
			//Debug.Log(ExpressionManager.GetCurrentType(simpleMotion.varID) + ":" + tmpStr4);
			if (ExpressionManager.GetCurrentType(simpleMotion.varID) == typeof(float))
			{
				if (!float.TryParse(tmpStr4, out tmpValue))
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "SETVARVALUE", row_id) + "对应的公式表参数ID的设置值填写错误！");
				}

				simpleMotion.varValue = tmpValue;
				
			}
			else if (ExpressionManager.GetCurrentType(simpleMotion.varID) == typeof(double))
			{
				if (!double.TryParse(tmpStr4, out tmpValue3))
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "SETVARVALUE", row_id) + "对应的公式表参数ID的设置值填写错误！");
				}

				simpleMotion.varValue = tmpValue3;

			}
			else if (ExpressionManager.GetCurrentType(simpleMotion.varID) == typeof(bool))
			{
				if (!bool.TryParse(tmpStr4, out tmpValue4))
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "SETVARVALUE", row_id) + "对应的公式表参数ID的设置值填写错误！");
				}

				simpleMotion.varValue = tmpValue4;

			}
			else if (ExpressionManager.GetCurrentType(simpleMotion.varID) == typeof(int))
			{
				if (!int.TryParse(tmpStr4, out tmpValue2))
				{
					Debug.LogError(ErrorLocation.Locate("PROGRAM", "SETVARVALUE", row_id) + "对应的公式表参数ID的设置值填写错误！");
				}

				simpleMotion.varValue = tmpValue2;
				
			}
			else{
				simpleMotion.varValue = tmpStr4;
				
			}
			

			simpleMotion.StandardTime = 0.01f;
			simpleMotion.EndTime = simpleMotion.StandardTime / simpleMotion.SpeedRate;
			motion_list.Add((IMotion)simpleMotion);

			//记录状态的状态
			if (Motion_Data.isEditor && MotionPlatformData.currentMotion == MotionPlatformState.Teaching)
			{
				Hashtable cameraHashTable = new Hashtable();

				for (int i = 0; i < VariableManager._varList.Count; i++)
				{
					//Debug.Log(i + "," + _simpleMotion.returnValue + "," + test[i]);
					if (simpleMotion.varID == VariableManager._varList[i])
					{
						cameraHashTable.Add(VariableManager._varList[i], simpleMotion.varValue);
					}
					else
					{
						cameraHashTable.Add(VariableManager._varList[i], VariableManager.GetValue(VariableManager._varList[i]));
					}
				}

				Type _t = Motion_TypeGet.MotionTypeGet("ReflectionManager");
				if (!MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MotionPlatformData.st_ReflectionManager = (MonoBehaviour)GameObject.FindObjectOfType(_t);
				}

				if (MotionPlatformData.st_ReflectionManager && _t != null)
				{
					MethodInfo methodInfo = _t.GetMethod("ReflectionAddState");
					BindingFlags flag = BindingFlags.Public | BindingFlags.Instance;
					object[] para = new object[] { MotionPlatformData.excelName, MotionPlatformData.mainRowNumber + 2, "State_Variables", "Variables", cameraHashTable };
					methodInfo.Invoke(MotionPlatformData.st_ReflectionManager, flag, Type.DefaultBinder, para, null);
				}
			}
			//装配表生成
			return true;
		}
	}
}


